﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OOLib
{
   /// <summary>
   /// Is an object which can be anchored in a text, like instances of TextFrame or TextField. 
   /// </summary>
   /// <remarks>
   /// If the concrete TextContent has a textual representation which fades into the surrounding text, then XTextField is used. 
   /// If the concrete TextContent has a "floating" object, like a graphic, ::com::sun::star::drawing::XShape is used.
   /// </remarks>
   public class TextContent : ComObjectWrapper
   {
      #region Constructors

      /// <summary>
      /// Constructor
      /// </summary>
      /// <remarks>
      /// After using this constructor, the ComObj must be set manually!
      /// </remarks>
      public TextContent() :
         base()
      { }

      /// <summary>
      /// Constructor
      /// </summary>
      /// <param name="comObject">COM object</param>
      public TextContent(object comObject) :
         base(comObject)
      { }

      #endregion

      #region XTextContent
      
      /// <summary>
      /// Is called when this object gets embedded in a text. 
      /// </summary>
      /// <param name="textRange">The tesxt range to attach.</param>
      /// <remarks>
      /// This acts like a multi-phase construction, thus the object may be invalid until it is attached to a text position. 
      /// In general, this method is called from within.
      /// Both text objects and text content objects may only be connected to each other if they are created by the same component.
      /// When implementing new components, this behaviour is deprecated.
      /// </remarks>
      public void Attach(TextRange textRange)
      {
         CheckDisposed();
         InvokeMethod("attach", textRange.ComObj);
      }

      /// <summary>
      /// Gets the text range to which the content is attached.
      /// </summary>
      /// <returns>Returns the text range to which the content is attached.</returns>
      /// <remarks>
      /// Note: The anchor of the actual implementation for text tables does not have a position in the text. 
      /// Thus that anchor can not be used for some operation like attach for example or insertTextContent or 
      /// other function that require the object to have a position in the text.
      /// The reason why a text table still needs an anchor is that for example tables should be insertable via 
      /// insertTextContent and that interface uses a parameter of that type.
      /// </remarks>
      public TextRange GetAnchor()
      {
         CheckDisposed();
         return new TextRange(InvokeMethod("getAnchor"));
      }

      #endregion

      #region properties

      /// <summary>
      /// Specifies how the text content is attached to its surrounding Text. 
      /// </summary>
      /// <remarks>
      /// Optional
      /// !!! Not tested !!!
      /// </remarks>
      public TextContentAnchorType AnchorType
      {
         get
         {
            CheckDisposed();
            return (TextContentAnchorType)GetProperty("AnchorType");
         }
         set
         {
            CheckDisposed();
            SetProperty("AnchorType", value);
         }
      }

      /// <summary>
      /// Gets the anchor type of the text content. 
      /// </summary>
      /// <remarks>
      /// Optional
      /// !!! Not tested !!!
      /// </remarks>
      public TextContentAnchorType[] AnchorTypes
      {
         get
         {
            CheckDisposed();
            return (TextContentAnchorType[])GetProperty("AnchorTypes");
         }
      }

      /// <summary>
      /// Gets or set if the text content is a shape and how the text is wrapped around the shape.
      /// </summary>
      /// <remarks>
      /// Optional
      /// !!! Not tested !!!
      /// </remarks>
      public WrapTextMode TextWrap
      {
         get
         {
            CheckDisposed();
            return (WrapTextMode)GetProperty("TextWrap");
         }
         set
         {
            CheckDisposed();
            SetProperty("TextWrap", value);
         }
      }

      #endregion
   }
}
